package com.lq.demo.demo.mode;


import sun.misc.BASE64Decoder;

import java.io.UnsupportedEncodingException;
import java.util.Base64;
import java.util.Base64.Encoder;

/**
 * @Auther: LQ
 * @Date: 2018/11/4 22:21
 * @Description:
 */
public class Test {

    public static void main(String[] args) throws Exception {
        String encrypt = encrypt("2121*212sasaQWFFF/S SAS[[]");
        System.out.println(encrypt);
        String decode = decode(encrypt);
        System.out.println(decode);
    }

    public static String encrypt(String str) throws UnsupportedEncodingException {
        Encoder encoder = Base64.getEncoder();
        byte[] encode = encoder.encode(str.getBytes());
        return new String(encode, "utf-8");
    }

    public static String decode(String str) throws Exception {
        return new String(new BASE64Decoder().decodeBuffer(str));
    }
}
